﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AgileLogistics.Model
{
   public class DBContext
    {
 

        public DBContext ()
        {
            this.DB = db;
            //添加Sql打印事件，开发中可以删掉这个代码
            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine(sql);
            };
        }



        public void CreateClass()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            Console.WriteLine("当前目录" + path);
            db.DbFirst.CreateClassFile(@"C:\Work\agile-logistics\Model\Models1", "AgileLogistics.Model");
        }

        public SqlSugarClient DB 
        {
            get;set;
            
        }


        //创建数据库对象
        SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = DBConfig.ConnectionString,//连接符字串
            DbType = DbType.SqlServer,
            IsAutoCloseConnection = true,
            

        });
    }
}
